package com.example.fin;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;

import com.example.fin.bean.FinItem;

public class EditFrame extends AppCompatActivity {
    private int id = -1;
    private String user = "zhiwen";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_frame);
        findViewById(R.id.btn_commit).setOnClickListener(view -> {
            FinItem item = new FinItem();
            item.setFee((int) Double.parseDouble(getValue(R.id.txt_fee)) * 100);
            item.setAmount((int) Double.parseDouble(getValue(R.id.txt_amount)) * 100);
            item.setUser(user);
            item.setDate(getValue(R.id.txt_date));
            item.setDate(getValue(R.id.txtRemark));
            CheckBox box = findViewById(R.id.cbx_mark);
            item.setMark(box.isSelected());
            item.setId(id);
            new DataSource(this).insertData(item);
            finish();
        });
    }

    private String getValue(int id) {
        EditText text = findViewById(id);
        return text.getText().toString();
    }

}